/*
 * 文件名：LogService.java	 
 * 时     间：下午9:39:20
 * 作     者：lyf      
 * 版     权： 2012-2022 湖南智软网络科技, 公司保留所有权利.
 * 联     系：http://www.073586.com/
 */
package com.local.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cz073586.tools.util.Tools;
import com.local.dao.hismappers.LocalPayBillMapper;
import com.local.dao.mapers.CarParkInMapper;
import com.local.dao.mapers.CarParkOutMapper;
import com.local.dao.mapers.LocalCouponMapper;
import com.local.dao.mapers.LogMapper;
import com.local.model.CarParkIn;
import com.local.model.CarParkOut;
import com.local.model.Log;
import com.local.model.LogExample;
import com.qianhai.common.dao.face.BaseMapper;
import com.qianhai.common.exception.BaseException;
import com.qianhai.common.service.impl.BaseServiceImpl;
import com.qianhai.common.utils.UUIDGenerateUtil;

/**
 * 类描述:这里是类描述
 * 
 * @ClassName: LogService
 * @author Administrator
 * @date 2015年10月10日 下午9:39:20
 */
@Service
public class LogService extends BaseServiceImpl<LogExample, Log, String>
		implements com.local.service.face.LogService
{
	
	@Autowired
	private LogMapper logMapper;
	
	@Autowired
	private CarParkOutMapper carParkOutMapper;
	
	@Autowired
	private CarParkInMapper carParkInMapper;
	
	@Autowired
	private LocalPayBillMapper localPayBillMapper;
	
	@Autowired
	private LocalCouponMapper localCouponMapper;
	
	@Override
	public Integer addLogInfo(Log log) throws BaseException
	{
		
		try
		{
			
			log.setUuid(UUIDGenerateUtil.generate());
			
			logMapper.insertSelective(log);
		} catch (Throwable t)
		{
			this.log.error(t.getMessage(), t);
			throw new BaseException(t.getMessage());
		}
		return null;
	}
	
	@Override
	public BaseMapper<LogExample, Log, String> getMapper()
	{
		return logMapper;
	}

	@Override
	public Integer getNOtHandleLogNumber()
	{
		LogExample ex = new LogExample();
		ex.or().andStatusEqualTo(1);//未处理状态
		
		return logMapper.countByCondition(ex);
	}

	@Override
	public Integer deleteCarInfoAndPayBill(CarParkOut carParkOut)
	{
		// TODO Auto-generated method stub
		try{
		//查找已出场的车辆
		carParkOut=carParkOutMapper.selectByPrimaryKey(carParkOut.getUuid());
		
		if(!Tools.isEmpty(carParkOut)&&!Tools.isEmpty(carParkOut.getCarInUuid())){
			
			//找到相对应的进场车辆数据
			CarParkIn carParkIn=carParkInMapper.selectByPrimaryKey(carParkOut.getCarInUuid());
			
			/*//获取进出场车辆的 流水数据
			LocalPayBillExample condition = new LocalPayBillExample();
			condition.or().andParkInUuidEqualTo(carParkIn.getUuid());
			List<LocalPayBill> list = localPayBillMapper.selectByCondition(condition);
			
			if(!Tools.isEmpty(list)&&list.size()>0){
				for(LocalPayBill lpb:list){
					//删除流水相对于的 优惠券列表
					LocalCouponExample conditionCou = new LocalCouponExample();
					conditionCou.or().andBillUuidEqualTo(lpb.getPayBillUuid());
					localCouponMapper.deleteByCondition(conditionCou);
				}
				//删除流水表中进场ID为
				localPayBillMapper.deleteByCondition(condition);
			}*/
			carParkInMapper.deleteByPrimaryKey(carParkOut.getCarInUuid());
			System.out.println("删除进场纪录成功！");
		}
		carParkOutMapper.deleteByPrimaryKey(carParkOut.getUuid());
		System.out.println("删除出场纪录成功！");
		} catch (Throwable t)
		{
			System.out.println(carParkOut.getCarNo() + ",删除进出场纪录失败..");
			log.error("", t);
		}
		return null;
	}
	
}
